<?php
/**
 * Created by lzl
 * Date: 2021 2021/9/26
 * Time: 14:10
 */
namespace App\Forms;


use App\Models\Plugin;

class PluginForms extends BaseForm
{

    /**
     * 插件中心
     * @return \Illuminate\Support\Collection
     */
    public function getPluginList()
    {
        return Plugin::get();
    }


    /**
     * @param $code
     * @return Plugin|\Illuminate\Database\Eloquent\Model|object|null
     */
    public function getDetail($code)
    {
        return Plugin::where('code', $code)->first();
    }

    /**
     * @param $validated
     * @return bool
     */
    public function install($validated)
    {

        switch ($validated['code']){
            case 'share_free':
                //TODO 一系列骚操作

                break;

            default:
                break;
        }

        Plugin::where('code', $validated['code'])->update(['status' => Plugin::ON]);

        return true;

    }

    /**
     * @param $id
     * @param $param
     * @return bool|int
     */
    public function edit($id, $param)
    {
        return Plugin::whereKey($id)->update($param);
    }


    /**
     * @param $id
     * @return Plugin|\Illuminate\Database\Eloquent\Model|object|null
     */
    public function getDetailById($id)
    {
        return Plugin::whereKey($id)->first();
    }

}